/*
 * BrokerQueue.cpp
 *
 */

#include "BrokerQueue.h"

namespace channel {

const std::string BrokerQueue::CHANNEL_QUEUE_PATH="/tmp/broker_queue_";
const char BrokerQueue::CHANNEL_QUEUE_KEY;

BrokerQueue::BrokerQueue(std::string brokerName):
		m_queue(ipc::MessageQueue<channel::ChannelMessage>::get(
				BrokerQueue::CHANNEL_QUEUE_PATH+brokerName,BrokerQueue::CHANNEL_QUEUE_KEY))
{

}

BrokerQueue::~BrokerQueue()
{
}

void BrokerQueue::create(std::string brokerName)
{
	ipc::MessageQueue<channel::ChannelMessage>::create(
					BrokerQueue::CHANNEL_QUEUE_PATH+brokerName,BrokerQueue::CHANNEL_QUEUE_KEY);
}

void BrokerQueue::destroy(std::string brokerName)
{
	ipc::MessageQueue<channel::ChannelMessage>::destroy(
					BrokerQueue::CHANNEL_QUEUE_PATH+brokerName,BrokerQueue::CHANNEL_QUEUE_KEY);
}

void BrokerQueue::recvFromReceiver(int receiverId,
		channel::ChannelMessage& message)
{
	message = m_queue.get(receiverId);
}

void BrokerQueue::sendToTransmiter(int transmiterId,
		channel::ChannelMessage& message)
{
	m_queue.put(transmiterId,message);
}

} /* namespace channel */
